﻿using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Meqs.Logic.Interface;
using System.Collections;
using Meqs.Entity;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    public string GetOpenedExamId()
    {
        if (SchoolCookie.ExamID > 0)
            return "true";
        else
            return "false";
    }

    public int GetCanUpload()
    {
        return SchoolCookie.CanUploadScore;
    }


    public string GetLoginInfo()
    {
        string s = "";
        s += "学区：" + CommonScore.GetAreaName;
        s += " ";
        s += "学校：" + CommonScore.SchoolName;
        s += " ";
        s += "姓名：" + CommonScore.GetUserName;
        s += " ";
        s += "工号：" + CommonScore.GetUserCode;
        return s;
    }

    protected void SetUserPerm()
    {
        //Response.Write("edumanage = " + (CommonScore.School_Edu_ManageExam ? "true;" : "false;"));
        //Response.Write("schoolmanage = " + (CommonScore.School_School_ShowReport ? "true;" : "false;"));
        //Response.Write("report = " + (CommonScore.SchoolShowReport ? "true;" : "false;"));
        //SchoolCommon.CheckRole((int)RoleKeyEnum.School_Header) ||
        if ( SchoolCommon.CheckRole((int)RoleKeyEnum.Teach_Director))
        {
            Response.Write("schoolmanage = true;edumanage=false;");
        }
        else
        {
            Response.Write("schoolmanage = false;edumanage=false;");
        }
    }
    protected string GetNowYearAndTerm
    {
        get
        {
            SchoolInfo si = SchoolCommon.Sch_SchoolInfo;
            return Common.ConvertYearAndTerm(si.SchoolYear, si.SchoolTerm);
        }
    }
    /// <summary>
    /// 修改密码
    /// </summary>
    /// <param name="schoolMark"></param>
    /// <returns></returns>
    [System.Web.Services.WebMethod]
    public static int UpdatePwd(string oldPwd, string newPwd)
    {
        //局级

        if (Common.GetUserInfo().UserType == 1 || Common.GetUserInfo().UserType == 2)
        {
            IEducationUsersLogic eduUserLogic = Container<IEducationUsersLogic>.Instance;

            Hashtable ht = new Hashtable();
            ht.Add("RID", Common.GetUserInfo().UID);
            ht.Add("Passwd", oldPwd);
            int iCount = eduUserLogic.FindCount(ht);

            if (iCount == 0) return -1;          //原密码不正确

            //重置密码
            List<int> list = new List<int>();
            list.Add(Common.GetUserInfo().UID);
            return eduUserLogic.ResetPwd(newPwd, list);
        }

        //校级
        if (Common.GetUserInfo().UserType == 3 || Common.GetUserInfo().UserType == 4)
        {
            ITeacherInfoLogic teacherLogic = Container<ITeacherInfoLogic>.Instance;

            Hashtable ht = new Hashtable();
            ht.Add("RID", Common.GetUserInfo().UID);
            ht.Add("Passwd", oldPwd);
            int iCount = teacherLogic.FindCount(ht);

            if (iCount == 0) return -1;          //原密码不正确

            //重置密码
            List<int> list = new List<int>();
            list.Add(Common.GetUserInfo().UID);
            return teacherLogic.ResetPassword(newPwd, list);
        }

        return 0;

    }

    /// <summary>
    /// 获取打开的考试名
    /// </summary>
    /// <param name="examId"></param>
    /// <returns></returns>
    public string GetOpenedExamName()
    {
        string examName = SchoolCookie.ExamName;
        return examName;
    }
}
